// index.js
Page({
  data: {
    // 页面数据
    unitTypes: [
      { id: 'length', name: '长度' },
      { id: 'area', name: '面积' },
      { id: 'weight', name: '重量' },
      { id: 'temperature', name: '温度' }
    ],
    darkMode: false
  },

  onLoad: function (options) {
    // 页面加载时执行
    this.checkDarkMode();
  },
  
  // 页面显示时执行
  onShow: function () {
    this.checkDarkMode();
  },

  // 检查夜间模式设置
  checkDarkMode: function () {
    const app = getApp();
    const darkMode = app.globalData.darkMode;
    this.setData({
      darkMode: darkMode
    });
  },

  // 夜间模式变化回调
  onDarkModeChange: function (darkMode) {
    this.setData({
      darkMode: darkMode
    });
  },

  // 跳转到换算页面
  goToConverter: function (e) {
    const type = e.currentTarget.dataset.type;
    
    wx.navigateTo({
      url: `/pages/converter/converter?type=${type}`
    });
  },
  
  // 跳转到历史记录页面
  goToHistory: function () {
    wx.navigateTo({
      url: '/pages/history/history'
    });
  }
});